<?php
require_once("../data/db_connection.php");
require_once("../constants.php");
require_once("../Utils.php");

$db = new db();

$relation_id = getFinalValue($_POST[PARAM_RELATION_ID]);
$relation_state = getFinalValue($_POST[PARAM_RELATION_STATE]);
$user_id = getFinalValue($_POST[PARAM_USER_ID]);
$friend_id = getFinalValue($_POST[PARAM_FRIEND_ID]);

$sql = "UPDATE pTableRelation SET pRelationState = 0 
		WHERE _id = " . $relation_id;
$return_id = $db->update_get_result($sql);

if ($return_id == 0) {
	// 如果第一条update就出错直接返回
	echo $return_id;
	break;
} else {
	$sql = "UPDATE pTableRelation SET pRelationState = 0
		 WHERE pUserId = " . $friend_id . "  and pFriendId = " . $user_id . ";";
	$return_id += $db->update_get_result($sql);
	echo $return_id;	
}

/*function confirmRelationState_1($relation_id) {
	global $db;
	$sql = "UPDATE pTableRelation SET pRelationState = 0 
		WHERE _id = " . $relation_id;
	$return_id = $db->update_get_result($sql);
	return $return_id;
}
		  
function confirmRelationState_2($user_id, $friend_id) {
	global $db;
	$sql = "UPDATE pTableRelation SET pRelationState = 0
		 WHERE pUserId = " . $friend_id . "  and pFriendId = " . $user_id . ";";
	$return_id = $db->update_get_result($sql);
	return $return_id;
}*/
?>